package club.twelveblog.tblog.controller;


import club.twelveblog.tblog.service.AdminService;
import club.twelveblog.tblog.service.BlogInfoService;
import club.twelveblog.tblog.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
/**
 * 上传个人头像Controller
 */
@Controller
@RequestMapping("/tblog/upload")
public class UploadImgController {

    @Autowired
    private UserService userService;
    @Autowired
    private AdminService adminService;
    @Autowired
    private BlogInfoService blogInfoService;

    /**
     * 用户头像上传
     * @param file
     * @return
     */
    @PostMapping("/authorImg")
    @ResponseBody
    public ResponseEntity<String> UploadUserImg(@RequestParam(value="file") MultipartFile file){
        String url=userService.UploadUserImg(file);
        return ResponseEntity.status(HttpStatus.OK).body(url);
    }

    /**
     * 管理员头像上传
     * @param file
     * @return
     */
    @PostMapping("/adminImg")
    @ResponseBody
    public ResponseEntity<String> UploadAdminImg(@RequestParam(value="file") MultipartFile file){
        String url=adminService.UploadAdminImg(file);
        return ResponseEntity.status(HttpStatus.OK).body(url);
    }

    /**
     * 博客文章图片上传
     * @param file
     * @return
     */
    @PostMapping("/blogImg")
    @ResponseBody
    public ResponseEntity<String> UploadBlogImg(@RequestParam(value="file") MultipartFile file){
        String url=blogInfoService.UploadBlogImg(file);
        return ResponseEntity.status(HttpStatus.OK).body(url);
    }

}
